/*  ------------------------------------------------------------------------  */
/*  Paper        : Does Stakeholder Outrage Determine Executive Pay?          */
/*  Program      : a02-10-propensityScore.do                                  */
/*  Description  : Matched sample analysis                                    */
/*  ------------------------------------------------------------------------  */

/*  ------------------------------------  */

use "$temp112/outragePanel.dta", clear

eststo drop *

xtset firm_id fyear
gen f2020_salary_cut1 = 2020.fyear#i1.dcut_all
	replace f2020_salary_cut1 = 0 if missing(f2020_salary_cut1)
tab fyear f2020_salary_cut1 if mainsample==1
tab fyear dcut_all if mainsample==1

gen firm_fe = 1
rename defer_rpt_as_comp_tot defer_rpt
rename defer_rpt_as_comp_tot_fr defer_rpt_fr

gen f2020 = fyear==2020

//  Compensation variables
#delimit ;
global compvars
	tdc1 salary varcomp bonus stock_awards_fv option_awards_fv
	noneq_incent othcomp defer_rpt
; #delimit cr

foreach yvar in $compvars {
	winsor2 `yvar', cuts(.5 99.5) suffix(_w)
}

//  Cash flows
foreach var of varlist mcap oancf ivncf fincf {
replace `var' = `var' / 1000
}
foreach yvar in oancf ivncf fincf {
	winsor2 `yvar', cuts(.5 99.5) suffix(_w)
}
foreach var of varlist boardSize ln_mcap lnEmp leverage_mkt oancf_w ceo_tenure {
gen `var'Lag = l1.`var'
}

/*  ------------------------------------------------------------------------  */
//  Propensity score sample

keep if inrange(fyear,2019,2021)
keep if mainsample==1

//  Firms with 2019-2020 data
gen _firm_id = 1 if inrange(fyear,2019,2020)
by firm_id _firm_id, sort: egen _firm_cnt = count(_firm_id)
by firm_id, sort: egen _twoYears = max(_firm_cnt)
gen _psmSample0 = 1 if _twoYears ==2
drop _twoYears _firm_cnt _firm_id
tab fyear _psmSample0

/*  ------------------------------------------------------------------------  */
//  Propensity score matching

psmatch2 f2020_salary_cut1 i.sic2_ctrl ln_mcapLag lnEmpLag leverage_mktLag ///
	oancf_wLag ceo_tenureLag boardSizeLag if fyear==2020 & _psmSample0==1, ///
	neighbor(1) noreplacement

tab _weight _treated


/*  ------------------------------------------------------------------------  */
//  Sample comparison

gen _treat = (_treated*-1)

xtset firm_id fyear
foreach var of varlist btm tangibility ret_std roa_std xrd_at payout_d boardTenure {
	gen `var'Lag = l1.`var'
	local lab: var label `var'
	label var `var'Lag "`lab'"
}

#delimit ;
local ch2020
	ln_mcapLag btmLag leverage_mktLag tangibilityLag ret_stdLag roa_stdLag xrd_atLag payout_dLag
	boardSizeLag boardTenureLag
; #delimit cr
summ `ch2020' if fyear==2020 & !missing(_weight)

local iff !missing(_weight)

eststo psm_yes: quietly estpost summarize `ch2020' if _treated==1 & `iff', detail
eststo psm_no: quietly estpost summarize `ch2020' if _treated==0 & `iff', detail
eststo psm_diff: quietly estpost ttest `ch2020' if `iff', by(_treat) unequal

/*  ------------------------------------------------------------------------  */
//  Mark PSM sample

gen _psmSample1 = 1 if !missing(_weight)
tab _psmSample1
order _psmSample1, first
by firm_id, sort: egen _psmSample2 = max(_psmSample1)
tab fyear _psmSample2
order _psmSample2, first
rename _psmSample2 psmSample2
drop _*

tab fyear f2020_salary_cut1 if psmSample2==1

/*  ------------------------------------------------------------------------  */
//  Regressions

#delimit ;
local salaryCutMain
	ln_mcap btm leverage_mkt tangibility ret_std roa_std xrd_at
	payout_d boardSize boardTenure prc_delta exret_202012
; #delimit cr

foreach iter in main {

di "----------------------"
di "Processing: `iter'"
di "----------------------"
local xvar ""
if inlist("`iter'","main") {
    local xvar f2020_salary_cut1 f2020
    local range 2020
}

foreach yvar in salary bonus stock_awards_fv option_awards_fv noneq_incent othcomp {

local fix if inrange(fyear,2019,`range') & mainsample==1 & psmSample2==1, a(firm_id) vce(cluster firm_id)
eststo frPS_`iter'_`yvar': qui reghdfe `yvar'_fr `xvar' `salaryCutMain' i.firm_fe `fix'

}
}

/*  ------------------------------------------------------------------------  */
//  Show results

// Matched sample covariate balance
#delimit ;
esttab psm_yes psm_no psm_diff,
	nonumbers nodepvars star(* 0.10 ** 0.05 *** 0.01)
	stats(N, fmt(%9.0fc) labels("Firms"))
	alignment(rrrrD{.}{.}{-1}r) width(1\linewidth)
	mgroups("No cut" "Salary cut" "Differences", pattern(1 1 1) ) nomtitles
	cells("
	sum_w(pattern(1 1 0) label(N) fmt(%9.0fc)) 
	mean(pattern(1 1 0) label(Mean) fmt(%9.3fc))
	p50(pattern(1 1 0) label(Median) fmt(%9.3fc))
	b(star pattern(0 0 1) label(Mean Delta) fmt(%9.3fc))
	t(pattern(0 0 1) label(t-stat) par fmt(3))")
	substitute("fill}l*{3}" "fill}l*{1}" " m)" "m)" " bn)" "bn)")
	label notes
; #delimit cr

// Matched sample analysis
#delimit ;
esttab frPS_main_*
 , b(%8.3f) t(%8.3f) star(* 0.10 ** 0.05 *** 0.01)
 nonotes nogap stats(r2_a N, layout(@ @) fmt(%8.3f %8.0fc)
 labels("Adjusted R2" "Onservations")) indicate("Firm FE =  *firm_fe*")
; #delimit cr


/*  -|----------------------------------------------------------------------  */
/*  ||  ---    Program end: a02-10-salaryCutMain.do                           */
/*  -|  ---    Attila Balogh    --------------------------------------------  */